package SGI.Dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import SGI.Excepcion.DAOExcepcion;
import SGI.Modelo.Asesoria;
import SGI.Util.ConexionBD;




public class DaoAsesoria  extends BaseDAO  {
	
	public Asesoria insertar(Asesoria vo) throws DAOExcepcion {
		String query = "insert into Asesoria(observacion, calificacion, asesor,ididea) values (?,?,?,?)";
		
		Connection con = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		
		try{
			con = ConexionBD.obtenerConexion();
			stmt = con.prepareStatement(query);
			
			stmt.setString(1, vo.getObservacion());
			stmt.setString(2, vo.getCalificacion());
			stmt.setInt(3, vo.getIdusuario());
			stmt.setInt(4, vo.getIdIdea());
			
			int i = stmt.executeUpdate();
			if (i != 1) {
				throw new SQLException("No se pudo insertar");
			}
			
		}catch (SQLException e) {
			System.err.println(e.getMessage());
			throw new DAOExcepcion(e.getMessage());
		}finally {
			this.cerrarResultSet(rs);
			this.cerrarStatement(stmt);
			this.cerrarConexion(con);
		}
		
		return vo;
	}
	
}